export default class ScorePanel {
  //记录分数和等级
  score = 0; //默认值就是0
  level = 1;
  maxLevel: number;
  upScore: number;
  scoreElement: HTMLElement;
  levelElement: HTMLElement;
  constructor(maxLevel: number = 10, upScore = 10) {
    //参数后面加等号是ES6 的 语法  即  如果不传参数  默认值就是10
    this.scoreElement = document.getElementById("score")!;
    this.levelElement = document.getElementById("level")!;
    this.maxLevel = maxLevel;
    this.upScore = upScore;
  }
  //加分方法
  addScore() {
    this.scoreElement.innerHTML = ++this.score + "";
    if (this.score % this.upScore === 0) {
      this.levelUp();
    }
  }
  //升级的方法
  levelUp() {
    //升级的条件 应该是由加分的函数来控制的
    //  等级跟速度挂钩  等级的提升是有上限的
    if (this.level < this.maxLevel) {
      this.levelElement.innerHTML = ++this.level + "";
    }
  }
}
